package com.indexingsystem.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.indexingsystem.boss.Vo.GamesReqVo;
import com.indexingsystem.boss.Vo.GamesTableVo;
import com.indexingsystem.boss.Vo.GamesVo;
import com.indexingsystem.boss.Vo.ResCategoryRelationsVo;
import com.indexingsystem.boss.admin.mapper.AuditLogsMapper;
import com.indexingsystem.boss.admin.mapper.DhResourceauditlogsMapper;
import com.indexingsystem.boss.admin.mapper.GamesMapper;
import com.indexingsystem.boss.admin.mapper.ResCategoryRelationsMapper;
import com.indexingsystem.boss.admin.mapper.ResourceRelationsMapper;
import com.indexingsystem.boss.admin.mapper.ResourceTypeMapper;
import com.indexingsystem.boss.admin.mapper.ResourcesMapper;
import com.indexingsystem.boss.admin.mapper.SpecialResourceDatasMapper;
import com.indexingsystem.boss.common.PagedResult;
import com.indexingsystem.boss.entity.AuditLogs;
import com.indexingsystem.boss.entity.DhResourceauditlogs;
import com.indexingsystem.boss.entity.DhTodayStorageInfos;
import com.indexingsystem.boss.entity.Games;
import com.indexingsystem.boss.entity.ResCategoryRelations;
import com.indexingsystem.boss.entity.ResourceCategors;
import com.indexingsystem.boss.entity.ResourceRelations;
import com.indexingsystem.boss.entity.ResourceType;
import com.indexingsystem.boss.entity.ResourceUpdateRecord;
import com.indexingsystem.boss.entity.Resources;
import com.indexingsystem.boss.entity.SpecialResourceDatas;
import com.indexingsystem.boss.utils.BeanUtils;
import com.indexingsystem.boss.utils.DateUtil;
import com.indexingsystem.boss.utils.InstitutionLoadUtils;
import com.indexingsystem.boss.utils.StringUtil;
import com.indexingsystem.db.mongoDB.impl.GamesResourceMongo;
import com.indexingsystem.db.mongoDB.impl.ResourceCategorsResListMongo;
import com.indexingsystem.db.mongoDB.po.GamesResourceMongoVo;
import com.indexingsystem.db.mongoDB.po.ResourceCategorsResPo;
import com.indexingsystem.system.service.IGamesService;
import com.indexingsystem.system.service.IResourceCategorsService;
import com.indexingsystem.system.service.IResourceUpdateRecordService;
import com.indexingsystem.system.service.IdhTodayStorageInfosService;

@Service
public class GamesServiceImpl implements IGamesService {

	@Resource
	private GamesMapper						gamesMapper;
	@Resource
	private ResourcesMapper					resourcesMapper;
	@Resource
	private ResCategoryRelationsMapper		resCategoryRelationsMapper;
	@Resource
	private SpecialResourceDatasMapper		specialResourceDatasMapper;

	@Resource
	private AuditLogsMapper					auditLogsMapper;

	@Resource
	private IdhTodayStorageInfosService		todayStorageInfosDao;

	@Resource
	private DhResourceauditlogsMapper		dhResourceauditlogsMapper;

	@Resource
	private ResourceRelationsMapper			resourceRelationsMapper;

	@Resource
	private ResourceTypeMapper				resourceTypeMapper;

	@Resource
	private IResourceUpdateRecordService	iResourceUpdateRecordService;

	@Resource
	private IResourceCategorsService		iResourceCategorsService;

	@Override
	public int deleteByPrimaryKey(String resId) {
		return gamesMapper.deleteByPrimaryKey( resId );
	}

	@Override
	public int insertSelective(Games record) {
		return gamesMapper.insertSelective( record );
	}

	@Override
	public PagedResult<GamesTableVo> selectGamesList(GamesVo gamesVo) {
		Integer pageNo = gamesVo.getPageNumber() == null ? 0 : gamesVo.getPageNumber();
		Integer pageSize = gamesVo.getPageSize() == null ? 10 : gamesVo.getPageSize();
		List<GamesTableVo> gamesTableVos = GamesResourceMongo.findGamesByPage( gamesVo, InstitutionLoadUtils.getString( "institutionId" ) );

		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNo, pageSize );
		if (null != gamesTableVos && gamesTableVos.size() > 0) {
			return BeanUtils.toPagedResult( gamesTableVos );
		} else {
			return BeanUtils.toPagedResult( gamesMapper.selectGamesList( gamesVo ) );
		}
	}

	@Override
	public Games selectByPrimaryKey(String resId) {
		return gamesMapper.selectByPrimaryKey( resId );
	}

	@Override
	public int updateByPrimaryKeySelective(Games record) {
		return gamesMapper.updateByPrimaryKeySelective( record );
	}

	@Override
	public Integer getGamesListCount(GamesVo gamesVo) {
		Integer maxCount = 0;
		maxCount = GamesResourceMongo.findGamesMaxCount( gamesVo, InstitutionLoadUtils.getString( "institutionId" ));
		if (maxCount == 0) {
			maxCount = gamesMapper.getGamesListCount( gamesVo );
		}
		return maxCount;
	}

	@Override
	public int addGamesInfo(GamesReqVo gamesReqVo, AuditLogs auditLogs, DhTodayStorageInfos dhTodayStorageInfos) throws Exception {
		int result = 0;
		if (null != gamesReqVo) {
			GamesResourceMongoVo gamesResourceMongoVo = new GamesResourceMongoVo();
			Resources resources = gamesReqVo.getResources();
			Games games = gamesReqVo.getGames();
			ResCategoryRelations resCategoryRelation = null;
			List<ResCategoryRelations> resultResCategoryRelationsList = null;
			List<ResCategoryRelationsVo> resCategoryRelationsVoList = gamesReqVo.getResCategoryRelationsList();
			if (null != resCategoryRelationsVoList && resCategoryRelationsVoList.size() > 0) {
				resultResCategoryRelationsList = new ArrayList<ResCategoryRelations>();
				for (ResCategoryRelationsVo resCategoryRela : resCategoryRelationsVoList) {
					resCategoryRelation = new ResCategoryRelations();
					resCategoryRelation.setResCategoryRelationId( resCategoryRela.getResCategoryRelationId() );
					resCategoryRelation.setResCategoryId( resCategoryRela.getResCategoryId() );
					resCategoryRelation.setResId( resCategoryRela.getResId() );
					if (!resultResCategoryRelationsList.contains( resCategoryRelation )) {
						resultResCategoryRelationsList.add( resCategoryRelation );
					}
				}
			}
			games.setGamesSize( games.getGamesSize() == null ? 0l : games.getGamesSize() );
			resourcesMapper.insertSelective( resources );

			gamesResourceMongoVo.setResId( resources.getResId() );
			gamesResourceMongoVo.setResTypeId( resources.getResTypeId() );
			gamesResourceMongoVo.setResTable( "Games" );
			gamesResourceMongoVo.setResources( resources );

			result = gamesMapper.insertSelective( games );
			gamesResourceMongoVo.setGames( games );
			if (null != resultResCategoryRelationsList && resultResCategoryRelationsList.size() > 0) {
				resCategoryRelationsMapper.insertResCategoryRelationsBatch( resultResCategoryRelationsList );
				for (ResCategoryRelationsVo resCategoryRela : resCategoryRelationsVoList) {
					// 登记资源分类资源变更表
					// 记录接触关系的资源
					ResourceUpdateRecord resourceUpdateRecord = new ResourceUpdateRecord();
					resourceUpdateRecord.setResourceUpdateRecordId( StringUtil.createSystemDataPrimaryKey() );
					resourceUpdateRecord.setResId( resCategoryRela.getResId() );
					ResourceType resType = resourceTypeMapper.selectResourceTypeResTableExits( "Games" );
					resourceUpdateRecord.setResTable( resType.getResTable() );
					resourceUpdateRecord.setResTypeId( resType.getResTypeId() );
					resourceUpdateRecord.setSuperCategoryId( resCategoryRela.getParentId() );
					resourceUpdateRecord.setResourceCategoryId( resCategoryRela.getResCategoryId() );
					resourceUpdateRecord.setOperatedate( DateUtil.getCurDate_YYYY_MM_DD() );
					resourceUpdateRecord.setState( "1" );
					iResourceUpdateRecordService.insert( resourceUpdateRecord );
				}
				gamesResourceMongoVo.setResCategoryRelationsList( resultResCategoryRelationsList );
			}

			// 报刊缓存mongo
			List<ResourceCategorsResPo> resourceCategorsResPoList = null;
			if (null != resultResCategoryRelationsList && resultResCategoryRelationsList.size() > 0) {
				resourceCategorsResPoList = new ArrayList<ResourceCategorsResPo>();
				for (ResCategoryRelations resCategoryRelations : resultResCategoryRelationsList) {
					ResourceCategorsResPo resourceCategorsResPo = new ResourceCategorsResPo();
					resourceCategorsResPo.setThumbnail( games.getFrontCover() );
					resourceCategorsResPo.setResType( 2 );
					String publishDate = resources.getPublishDate();

					resourceCategorsResPo.setDatePx( DateUtil.parseFormatToPublishDate( publishDate ) );
					resourceCategorsResPo.setPublishDate( publishDate );

					resourceCategorsResPo.setResId( resCategoryRelations.getResId() );
					resourceCategorsResPo.setResName( resources.getResName() );
					resourceCategorsResPo.setPublishDate( resources.getPublishDate() );
					resourceCategorsResPo.setResTypeId( resources.getResTypeId() );
					resourceCategorsResPo.setResCategoryId( resCategoryRelations.getResCategoryId() );
					resourceCategorsResPo.setStatus( resources.getStatus() );

					// 通过资源分类id获取资源分类名称
					ResourceCategors resourceCategors = iResourceCategorsService.selectByPrimaryKey( resCategoryRelations.getResCategoryId() );
					resourceCategorsResPo.setResCategoryName( resourceCategors.getResName() );
					resourceCategorsResPo.setResTable( "Games" );

					if (!resourceCategorsResPoList.contains( resourceCategorsResPo )) {
						resourceCategorsResPoList.add( resourceCategorsResPo );
					}
				}
				ResourceCategorsResListMongo.addResourceCategorsResList( resourceCategorsResPoList, InstitutionLoadUtils.getString( "institutionId" ) );
			}

			List<SpecialResourceDatas> specialResourceDatasList = gamesReqVo.getSpecialResourceDatasList();
			if (null != specialResourceDatasList && specialResourceDatasList.size() > 0) {
				specialResourceDatasMapper.batchAddSpecialResourceDatas( specialResourceDatasList );
				gamesResourceMongoVo.setDhSpecialResourceDatasList( specialResourceDatasList );
			}
			auditLogsMapper.insertSelective( auditLogs );
			gamesResourceMongoVo.setAuditLogs( auditLogs );

			// 判斷資源ID是否存在
			DhResourceauditlogs resAuditLogsList = dhResourceauditlogsMapper.getResAuditlogsByResId( resources.getResId() );
			if (null == resAuditLogsList) {
				DhResourceauditlogs resourceauditlogs = new DhResourceauditlogs();
				resourceauditlogs.setCreatedate( DateUtil.parseFormatToDate( DateUtil.getCurTotalDate() ) );
				resourceauditlogs.setDescription( "游戏源类型批量入库" );
				resourceauditlogs.setHandler( resources.getCreateUserId() == null ? "admin" : resources.getCreateUserId() );
				resourceauditlogs.setStatus( 0 );
				resourceauditlogs.setResid( resources.getResId() );
				resourceauditlogs.setId( StringUtil.createSystemDataPrimaryKey() );
				dhResourceauditlogsMapper.insertSelective( resourceauditlogs );
				gamesResourceMongoVo.setResourceauditlogs( resourceauditlogs );
			} else {
				gamesResourceMongoVo.setResourceauditlogs( resAuditLogsList );
			}

			todayStorageInfosDao.insert( dhTodayStorageInfos );
			gamesResourceMongoVo.setTodayStorageInfos( dhTodayStorageInfos );

			// 资源关系列表
			List<ResourceRelations> resourceRelationsList = resourceRelationsMapper.getResourceRelationsListByResId( gamesReqVo.getResources()
					.getResId() );
			if (null != resourceRelationsList && resourceRelationsList.size() > 0) {
				gamesResourceMongoVo.setDhResourceRelationsList( resourceRelationsList );
			}

			GamesResourceMongo.addGames( gamesResourceMongoVo, InstitutionLoadUtils.getString( "institutionId" ) );
		}
		return result;
	}

	@Override
	public int updateGamesInfo(GamesReqVo gamesReqVo) throws Exception {
		int result = 0;
		if (null != gamesReqVo) {
			GamesResourceMongoVo gamesResourceMongoVo = new GamesResourceMongoVo();
			Resources resources = gamesReqVo.getResources();
			Games games = gamesReqVo.getGames();
			ResCategoryRelations resCategoryRelation = null;
			List<String> resIdList = null;
			List<String> resCategoryIdList = null;
			List<ResCategoryRelations> resultResCategoryRelationsList = null;
			List<ResCategoryRelationsVo> resCategoryRelationsVoList = gamesReqVo.getResCategoryRelationsList();
			if (null != resCategoryRelationsVoList && resCategoryRelationsVoList.size() > 0) {
				resIdList = new ArrayList<String>();
				resCategoryIdList = new ArrayList<String>();
				resultResCategoryRelationsList = new ArrayList<ResCategoryRelations>();
				for (ResCategoryRelationsVo resCategoryRela : resCategoryRelationsVoList) {
					resCategoryRelation = new ResCategoryRelations();
					resCategoryRelation.setResCategoryRelationId( StringUtil.createSystemDataPrimaryKey() );
					resCategoryRelation.setResCategoryId( resCategoryRela.getResCategoryId() );
					resCategoryRelation.setResId( resCategoryRela.getResId() );
					resCategoryIdList.add( resCategoryRela.getResCategoryId() );
					resIdList.add( resCategoryRela.getResId() );
					if (!resultResCategoryRelationsList.contains( resCategoryRelation )) {
						resultResCategoryRelationsList.add( resCategoryRelation );
					}
				}
			}
			List<SpecialResourceDatas> specialResourceDatasList = gamesReqVo.getSpecialResourceDatasList();
			resourcesMapper.updateByPrimaryKeySelective( resources );
			Resources resourcesObj = resourcesMapper.selectByPrimaryKey( resources.getResId() );

			gamesResourceMongoVo.setResId( resourcesObj.getResId() );
			gamesResourceMongoVo.setResTypeId( resourcesObj.getResTypeId() );
			gamesResourceMongoVo.setResTable( "Games" );
			gamesResourceMongoVo.setResources( resourcesObj );

			result = gamesMapper.updateByPrimaryKeySelective( games );
			Games gamesObj = gamesMapper.selectByPrimaryKey( games.getResId() );
			gamesResourceMongoVo.setGames( gamesObj );

			// 先删后加
			resCategoryRelationsMapper.deleteResBatchCategoryRelationsByResId( resIdList );
			if (null != resultResCategoryRelationsList && resultResCategoryRelationsList.size() > 0) {
				// 后加
				resCategoryRelationsMapper.insertResCategoryRelationsBatch( resultResCategoryRelationsList );
				for (ResCategoryRelations resCategoryRelations : resultResCategoryRelationsList) {
					// 登记资源分类资源变更表
					// 记录接触关系的资源
					ResourceUpdateRecord resourceUpdateRecord = new ResourceUpdateRecord();
					resourceUpdateRecord.setResourceUpdateRecordId( StringUtil.createSystemDataPrimaryKey() );
					resourceUpdateRecord.setResId( resCategoryRelations.getResId() );
					ResourceType resType = resourceTypeMapper.selectResourceTypeResTableExits( "Games" );
					resourceUpdateRecord.setResTable( resType.getResTable() );
					resourceUpdateRecord.setResTypeId( resType.getResTypeId() );
					ResourceCategors resourceCategors = iResourceCategorsService.selectByPrimaryKey( resCategoryRelations.getResCategoryId() );
					resourceUpdateRecord.setSuperCategoryId( resourceCategors.getParentId() );
					resourceUpdateRecord.setResourceCategoryId( resCategoryRelations.getResCategoryId() );
					resourceUpdateRecord.setOperatedate( DateUtil.getCurDate_YYYY_MM_DD() );
					resourceUpdateRecord.setState( "1" );
					iResourceUpdateRecordService.insert( resourceUpdateRecord );
				}
				gamesResourceMongoVo.setResCategoryRelationsList( resultResCategoryRelationsList );

				// 先通过resId清理所有分类列表
				List<String> delResIdList = new ArrayList<String>();
				delResIdList.add( resources.getResId() );
				ResourceCategorsResListMongo.deleteResCategoryRelationsByResId( delResIdList, InstitutionLoadUtils.getString( "institutionId" ) );

				// 重新缓存新的资源分类关系
				List<ResourceCategorsResPo> resourceCategorsResPoList = null;
				if (null != resultResCategoryRelationsList && resultResCategoryRelationsList.size() > 0) {
					resourceCategorsResPoList = new ArrayList<ResourceCategorsResPo>();
					for (ResCategoryRelations resCategoryRelations : resultResCategoryRelationsList) {
						ResourceCategorsResPo resourceCategorsResPo = new ResourceCategorsResPo();
						resourceCategorsResPo.setThumbnail( games.getFrontCover() );
						resourceCategorsResPo.setResType( 2 );
						String publishDate = resources.getPublishDate();

						resourceCategorsResPo.setDatePx( DateUtil.parseFormatToPublishDate( publishDate ) );
						resourceCategorsResPo.setPublishDate( publishDate );

						resourceCategorsResPo.setResId( resCategoryRelations.getResId() );
						resourceCategorsResPo.setResName( resources.getResName() );
						resourceCategorsResPo.setPublishDate( resources.getPublishDate() );
						resourceCategorsResPo.setResTypeId( resources.getResTypeId() );
						resourceCategorsResPo.setResCategoryId( resCategoryRelations.getResCategoryId() );
						resourceCategorsResPo.setStatus( resources.getStatus() );

						// 通过资源分类id获取资源分类名称
						ResourceCategors resourceCategors = iResourceCategorsService.selectByPrimaryKey( resCategoryRelations.getResCategoryId() );
						resourceCategorsResPo.setResCategoryName( resourceCategors.getResName() );
						resourceCategorsResPo.setResTable( "Games" );

						if (!resourceCategorsResPoList.contains( resourceCategorsResPo )) {
							resourceCategorsResPoList.add( resourceCategorsResPo );
						}
					}
					ResourceCategorsResListMongo.addResourceCategorsResList( resourceCategorsResPoList, InstitutionLoadUtils.getString( "institutionId" ) );
				}
			}
			if (null != specialResourceDatasList && specialResourceDatasList.size() > 0) {
				// 终端先删后加
				specialResourceDatasMapper.deleteSpecialResourceDatasByIdBatch( resIdList );

				// 新增流水号
				specialResourceDatasMapper.batchAddSpecialResourceDatas( specialResourceDatasList );
			}
			gamesResourceMongoVo.setDhSpecialResourceDatasList( specialResourceDatasList );

			AuditLogs auditLogs = null;
			List<AuditLogs> auditLogsList = auditLogsMapper.getAuditLogsListByResId( gamesReqVo.getResources().getResId() );
			if (null != auditLogsList && auditLogsList.size() > 0) {
				auditLogs = auditLogsList.get( 0 );
			}
			gamesResourceMongoVo.setAuditLogs( auditLogs );

			DhResourceauditlogs dhResourceAuditLogs = dhResourceauditlogsMapper.getResAuditlogsByResId( gamesReqVo.getResources().getResId() );
			gamesResourceMongoVo.setResourceauditlogs( dhResourceAuditLogs );

			DhTodayStorageInfos dhTodayStorageInfos = null;
			List<DhTodayStorageInfos> todayStorageInfosList = todayStorageInfosDao.getDhTodayStorageInfosByResId( gamesReqVo.getResources()
					.getResId() );
			if (null != todayStorageInfosList && todayStorageInfosList.size() > 0) {
				dhTodayStorageInfos = todayStorageInfosList.get( 0 );
			}
			gamesResourceMongoVo.setTodayStorageInfos( dhTodayStorageInfos );

			// 资源关系列表
			List<ResourceRelations> resourceRelationsList = resourceRelationsMapper.getResourceRelationsListByResId( gamesReqVo.getResources()
					.getResId() );
			if (null != resourceRelationsList && resourceRelationsList.size() > 0) {
				gamesResourceMongoVo.setDhResourceRelationsList( resourceRelationsList );
			}
			GamesResourceMongo.updateGames( gamesResourceMongoVo, InstitutionLoadUtils.getString( "institutionId" ) );
		}
		return result;
	}

	@Override
	public int deleteGamesByIdBatch(List<String> resIdList) throws Exception {
		int result = 0;
		if (null != resIdList && resIdList.size() > 0) {
			for (String resId : resIdList) {
				Games queryGames = selectByPrimaryKey( resId );
				if (null != queryGames) {
					// 1、删除
					result += deleteByPrimaryKey( queryGames.getResId() );
					// 第二步删除资源分类关系
					List<ResCategoryRelations> resCategoryRelationList = resCategoryRelationsMapper.getResCategoryRelationsListByResId( queryGames
							.getResId() );
					for (ResCategoryRelations resCategoryRelations : resCategoryRelationList) {
						resourceRelationsMapper.deleteByPrimaryKey( resCategoryRelations.getResCategoryRelationId() );
						// 登记资源分类资源变更表
						// 记录接触关系的资源
						ResourceUpdateRecord resourceUpdateRecord = new ResourceUpdateRecord();
						resourceUpdateRecord.setResourceUpdateRecordId( StringUtil.createSystemDataPrimaryKey() );
						resourceUpdateRecord.setResId( resCategoryRelations.getResId() );
						ResourceType resType = resourceTypeMapper.selectResourceTypeResTableExits( "Games" );
						resourceUpdateRecord.setResTable( resType.getResTable() );
						resourceUpdateRecord.setResTypeId( resType.getResTypeId() );
						ResourceCategors resourceCategors = iResourceCategorsService.selectByPrimaryKey( resCategoryRelations.getResCategoryId() );
						resourceUpdateRecord.setSuperCategoryId( resourceCategors.getParentId() );
						resourceUpdateRecord.setResourceCategoryId( resCategoryRelations.getResCategoryId() );
						resourceUpdateRecord.setOperatedate( DateUtil.getCurDate_YYYY_MM_DD() );
						resourceUpdateRecord.setState( "0" );
						iResourceUpdateRecordService.insert( resourceUpdateRecord );
					}

					// 第三步删除资源关系
					// 资源关系列表
					List<ResourceRelations> queryResRelationsList = resourceRelationsMapper.getResourceRelationsListByResId( queryGames.getResId() );
					for (ResourceRelations resRelations : queryResRelationsList) {
						resourceRelationsMapper.deleteByPrimaryKey( resRelations.getResRelationId() );
					}

					// 第四步：删除资源终端关系
					List<SpecialResourceDatas> tempSpecialResDataList = specialResourceDatasMapper.getSpecialResourceDataListByResId( queryGames
							.getResId() );
					for (SpecialResourceDatas resSpecialDatas : tempSpecialResDataList) {
						specialResourceDatasMapper.deleteBySpecialResourceDataId( resSpecialDatas.getSpecialResDataId() );
					}

					// 5、删除审核日志表关系
					List<AuditLogs> auditLogsList = auditLogsMapper.getAuditLogsListByResId( queryGames.getResId() );
					for (AuditLogs auditLogs : auditLogsList) {
						auditLogsMapper.deleteByPrimaryKey( auditLogs.getProductLogId() );
					}

					// 清理入库审核日志表关系
					DhResourceauditlogs dhResourceAuditLogs = dhResourceauditlogsMapper.getResAuditlogsByResId( queryGames.getResId() );
					if (null != dhResourceAuditLogs) {
						dhResourceauditlogsMapper.deleteByPrimaryKey( dhResourceAuditLogs.getId() );
					}

					// 删除流水
					List<DhTodayStorageInfos> dhTodayStorageInfosList = todayStorageInfosDao.getDhTodayStorageInfosByResId( queryGames.getResId() );
					for (DhTodayStorageInfos dhTodayStorageInfos : dhTodayStorageInfosList) {
						todayStorageInfosDao.deleteTodayStorageInfoById( dhTodayStorageInfos.getStorageId() );
					}

					resourcesMapper.deleteByPrimaryKey( resId );
				}

			}
			GamesResourceMongo.deleteGamesByIds( resIdList, InstitutionLoadUtils.getString( "institutionId" ) );

			// 先清理资源所有分类关系
			ResourceCategorsResListMongo.deleteResCategoryRelationsByResId( resIdList, InstitutionLoadUtils.getString( "institutionId" ) );
		}
		return result;
	}
}